﻿// <copyright file="CrossDomainService.svc.cs" company="company"> 
// (C) 2010 . All rights reserved
// </copyright>
// <author>Lukasz Bartczak</author>
namespace WcfService1
{
    using System;
    using System.IO;
    using System.ServiceModel;
    using System.ServiceModel.Channels;
    using System.Xml;

    /// <summary>
    /// CrossDomainService implementation
    /// </summary>
    public class CrossDomainService : ICrossDomainService
    {
        /// <summary>
        /// Provides the policy file.
        /// </summary>
        /// <returns>Service channel message</returns>
        public Message ProvidePolicyFile()
        {
            try
            {
                FileStream filestream = File.Open(@"ClientAcessPolicy.xml", FileMode.Open);
                //// Either specify ClientAcessPolicy.xml file path properly
                //// or put that in \Bin folder of the console application
                XmlReader reader = XmlReader.Create(filestream);
                System.ServiceModel.Channels.Message result = Message.CreateMessage(MessageVersion.None, string.Empty, reader);
                return result;
            }
            catch (FaultException fe)
            {
                throw new FaultException(fe.Reason, fe.Code, "Exception in ProvidePolicyFile");
            }
            catch (CommunicationException cex)
            {
                throw new CommunicationException("Exception in ProvidePolicyFile " + cex.Message, cex.InnerException);
            }
            catch (Exception exe)
            {
                throw new Exception("Exception in ProvidePolicyFile " + exe.Message, exe.InnerException);
            }
        }
    }
}
